package main.java;

/**
 * Write a description of class Planete here.
 * 
 * @author cmeulien
 * @version (a version number or a date)
 */
public class Planete
{
	
	// instance variables - replace the example below with your own
    private float diametre;
    private float masse;
    private Galaxie g;
    

    /**
     * Constructor for objects of class Planete
     */
    public Planete(Galaxie g) throws Exception   {
        // initialise instance variables
    	if (g == null)
    		throw new Exception("Pas de galaxie");
    	this.g = g;
    	this.diametre=1;
    	this.masse=1;
    }
    
    public Planete(float d, float m, Galaxie g) throws Exception{
    	if( d < 0)
    		throw new Exception("Diametre negatif");
    	if( m < 0)
    		throw new Exception("Masse negatif");
    	if (g == null)
    		throw new Exception("Pas de galaxie");
    	this.g = g;
    	g.addPlanete(this);
        diametre = d;
        masse = m;
    }
  
    public void setDiametre( float d )  throws Exception{
    	if( d < 0)
    		throw new Exception("Diametre negatif");
        diametre = d;
    }
    public float getDiametre(){
        return diametre;
    }
    public void setMasse( float m )  throws Exception{
    	if( m < 0)
    		throw new Exception("Masse negatif");
        masse = m;
    }
    public float getMasse(){
        return masse;
    }
    
    public void removeGalaxie() {
    	this.g = null;    	
    }
    public void setGalaxie(Galaxie g){
    	if ( g.equals(this.g) )
    		return;
    	if(this.g!=null)
    		this.g.removePlanete(this);
    	this.g = g;
	    g.addPlanete(this);
    }
    
    public Galaxie getGalaxie(){
    	return this.g;
    }
    
    public String toString(){
    	return "la plannete a le diametre : " + masse;
    }
    
}